package com.woniu.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.entity.FlowerComment;
import com.woniu.mapper.FlowerCommentMapper;
import com.woniu.service.FlowerCommentService;
import com.woniu.vo.FlowerCommentVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @program:
 * @ClassName:
 * @description:
 * @author: zgc
 * @date:
 * @Version 1.0
 **/
@Service
public class FlowerCommentServiceImpl implements FlowerCommentService {
    @Resource
    private FlowerCommentMapper flowerCommentMapper;
    
    // 修改举报评论状态
    @Override
    public int updatecomplaintFlowerCommentByCommentId(FlowerComment flowerComment) {
        return flowerCommentMapper.updateByPrimaryKeySelective(flowerComment);
    }
    //查看评价详情
    @Override
    public FlowerCommentVo selectFlowerCommentByCommentId(FlowerComment flowerComment) {
        return flowerCommentMapper.selectFlowerCommentByCommentId(flowerComment);
    }
    //查询所有评价

    @Override
    public PageInfo<FlowerCommentVo> selectAllFlowerComments(Integer pageNum, Integer pageSize, String flowerName, String accountName, Long startTime, Long endTime, Integer rateScore, Integer isDelete) {
        PageHelper.startPage(pageNum,pageSize);
        if (startTime != null && endTime != null) {
            Date startTimedate = new Date(startTime);
            Date endTimedate = new Date(endTime);
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            String startTimedate1 = simpleDateFormat.format(startTimedate).substring(0,10)+" 00:00:00";

            String endTimedate1 = simpleDateFormat.format(endTimedate).substring(0,10)+" 23:59:59";
            List<FlowerCommentVo> list = flowerCommentMapper.selectAllFlowerComments(flowerName, accountName,startTimedate1,endTimedate1,rateScore,isDelete);
            return new PageInfo<FlowerCommentVo>(list);
        }
        List<FlowerCommentVo> list = flowerCommentMapper.selectAllFlowerComments(flowerName, accountName,null,null,rateScore,isDelete);
        return new PageInfo<>(list);
    }
    
}
